package com.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Discription:
 */
public class ContextServlet1 extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取ServletContext对象
        ServletContext context = getServletContext();
        //与getServletConfig().getServletContext();方法相同

        System.out.println("保存前： Context1 中获取数据key1:"+context.getAttribute("key1"));
        context.setAttribute("key1","value1");

        System.out.println("Context1 中获取数据key1:"+context.getAttribute("key1"));

    }
}
